package leetcode.code0949;

import leetcode.IDebug;
import leetcode.helper.H;

public class Solution implements IDebug {

	public String largestTimeFromDigits(int[] arr) {
		String ans = "";
		for (int a = 0; a < arr.length; a++) {
			for (int b = 0; b < arr.length; b++) {
				if (b != a) {
					for (int c = 0; c < arr.length; c++) {
						if (c != a && c != b) {
							String cur = process(a, b, c, 6 - a - b - c, arr);
							if (cur != null && cur.compareTo(ans) > 0) {
								ans = cur;
							}
						}
					}
				}
			}
		}
		return ans;
	}

	private String process(int a, int b, int c, int d, int[] arr) {
		int hour = arr[a] * 10 + arr[b];
		int minute = arr[c] * 10 + arr[d];
		if (hour >= 24 || minute >= 60) {
			return null;
		}
		StringBuffer sb = new StringBuffer();
		sb.append((char) (arr[a] + '0')).append((char) (arr[b] + '0')).append(":").append((char) (arr[c] + '0'))
				.append((char) (arr[d] + '0'));
		return sb.toString();
	}

	@Override
	public void debug4() {
		H.compare("23:41", this.largestTimeFromDigits(H.str2array3("[1,2,3,4]")));
		H.compare("", this.largestTimeFromDigits(H.str2array3("[5,5,5,5]")));
		H.compare("00:00", this.largestTimeFromDigits(H.str2array3("[0,0,0,0]")));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
